# coding=UTF-8

"""
import dash
import dash_core_components
import dash_html_components
import numpy
 
t = numpy.linspace(0, 2 * numpy.pi, 100)
x = 10 * (2 * numpy.sin(t) - numpy.sin(2 * t))
y = 10 * (2 * numpy.cos(t) - numpy.cos(2 * t))
 
app = dash.Dash()
 
app.layout = dash_html_components.Div(children=[
    dash_html_components.H1(children='Hello! Dash love you! '),
 
    dash_core_components.Graph(
        id='heart-curve',
        figure={
            'data': [
                {'x': x, 'y': y, 'type': 'Scatter', 'name': 'Heart'},
            ],
            'layout': {
                'title': 'Heart Curve'
            }
        }
    )
])
 
if __name__ == '__main__':
    app.run_server(host="127.0.0.1")
    
"""



import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
from datetime import datetime as dt
import tushare as ts
 
app = dash.Dash()
 
app.layout = html.Div([
    html.H1('k-30'),
    dcc.Dropdown(
        id='my-dropdown',
        options=[
            {'label': '爱柯迪', 'value':'600933'},
            {'label': '赣锋锂业', 'value':'002460'},
            {'label': '中国神华', 'value':'601088'},
            {'label': '广汽集团', 'value':'601238'},
            {'label': '春秋航空', 'value':'601021'},
        ],
        value='600933'
    ),
    dcc.Graph(id='my-graph')
])
 
 
@app.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
    # df = web.DataReader(
    #     selected_dropdown_value, data_source='yahoo',
    #     start=dt(2018, 1, 1), end=dt.now()
    # )
 
    df = ts.get_k_data(selected_dropdown_value, ktype='30')
 
    return {
        'data': [
            {
            'x': df.index,
            'y': df.close
            }
        ]
    }
 
if __name__ == '__main__':
    app.run_server(host="127.0.0.1")    
 